class Solution5 {
    public boolean evaluateTree(TreeNode root) {
        if(root.left == null && root.right == null) {
            if(root.val == 0) {
                return false;
            }
            return true;
        }
        boolean rootleft = evaluateTree(root.left);
        boolean rootright = evaluateTree(root.right);
        if(root.val == 2) {
            return rootleft | rootright;
        }
        return rootleft & rootright;
    }
}